;(function(w, u) {u(w);
}(window, function(window) {
	var at = function (selector, context) {return new at.fn.init(selector, context);};
	at.fn = at.prototype;
	at.fn.init = function (selector, context) {
		var nodeList = [];
		if (typeof(selector) == 'string') {
			nodeList = (context || document).querySelectorAll(selector);
		} else if (selector instanceof Node) {
			nodeList[0] = selector;
		} else if (selector instanceof NodeList || selector instanceof Array) {
			nodeList = selector;
		}
		this.length = nodeList.length;
		for (var i = 0; i < this.length; i += 1) {
			this[i] = nodeList[i];
		}
		return this;
	};
	at.fn.init.prototype = at.fn
	/************
	* Dom 操作
	************/
	// 遍历
	at.fn.each = function (fun, ret) {
		var res = [];
		for (var i = 0; i < this.length; i++) {
			res[i] = fun.call(this[i]);
		}
		if (ret) {
			if (res.length == 1) {res = res[0];}
			return res;
		}
		return this;
	};
	// 获取第i个元素  |  例：at('.class').eq(i)
	at.fn.eq = function () {
		var nodeList = [];
		for (var i = 0; i < arguments.length; i++) {
			nodeList[i] = this[arguments[i]];
		};return at(nodeList);
	};
	
	// 获取第一个元素  |  例：at('.class').first()
	at.fn.first = function () { return this.eq(0);};
	
	// 获取最后一个元素  |  例：at('.class').last()
	at.fn.last = function () { return this.eq(this.length - 1);};
	
	// 用于元素查找,支持id,class,标签等选择器  | 例：at('.class').find('.class').find('a')
	at.fn.find = function (str) {
		var nodeList = [];
		var res = this.each(function () {return this.querySelectorAll(str);}, 1);
		if (res instanceof Array) {
			for (var i = 0; i < res.length; i++) {
				for (var j = 0; j < res[i].length; j++) {
					nodeList.push(res[i][j]);
				}
			}
		} else {nodeList = res;}
		return at(nodeList);
	};
	
	// 用于返回被选元素的直接父元素  | 例：at('.class').parent()
	at.fn.parent = function () {return at(this.each(function () {return this.parentNode;}, 1));};
	
	// 用于元素 隐藏/显示  | 例：at('.class').hide();  at('.class').show();
	at.fn.hide = function () {return this.each(function () {this.style.display = "none";});};
	at.fn.show = function () {return this.each(function () {this.style.display = "";});};
	
	// 用于文本修改/获取  | 例：at('.class').text();  at('.class').text(str)；
	at.fn.text = function (str) {
		if (str != undefined) {
			return this.each(function () {this.innerText = str;});
		} else {
			return this.each(function () {return this.innerText;}, 1);
		}
	};
	
	// 设置/获取对象及其内容的HTML形式 | 例：at().tag('p').text("hello").attr('id','test').outHtml();
	at.fn.outHtml = function (str) {
		if (str != undefined) {
			return this.each(function () {this.outerHTML = str;});
		} else {
			return this.each(function () {return this.outerHTML;}, 1);
		}
	};
	
	// 设置/获取位于对象起始和结束标签内的HTML | 例：at('.class').html();  at('.class').html(str);
	at.fn.html = function (str) {
		if (str != undefined) {
			return this.each(function () {this.innerHTML = str;});
		} else {
			return this.each(function () {return this.innerHTML;}, 1);
		}
	};
	
	// 设置/获取输入值 | 例：at('.class').val();  at('.class').val(str);
	at.fn.val = function (str) {
		if (str != undefined) {
			return this.each(function () {this.value = str;});
		} else {
			return this.each(function () {return this.value;}, 1);
		}
	};
	
	// 设置/获取css样式 | 例：at('.class').css('color',['red']);?
	at.fn.css = function (key, value, important) {
		if (value != undefined) {
			return this.each(function () {this.style.setProperty(key, value, important);});
		} else {
			return this.each(function () {return this.style.getPropertyValue(key);}, 1);
		}
	};
	
	// 设置/获取属性 | 例：at('.class').attr('key','val'); at('.class').attr('key');
	at.fn.attr = function (key, value) {
		if (value != undefined) {
			return this.each(function () {this.setAttribute(key, value);});
		} else {
			return this.each(function () {return this.getAttribute(key);}, 1);
		}
	};
	
	// 删除属性值 | 例：at('.class').removeAttr('class')
	at.fn.removeAttr = function (key) {
		return this.each(function () {this.removeAttribute(key);});
	};
	
	// 删除元素 | 例：at('.class').remove()
	at.fn.remove = function () {
		return this.each(function () {this.remove();});
	};
	
	// 在元素末尾插入内容 | 例：at('.class').append(str)
	at.fn.append = function (str) {
		return this.each(function () {this.insertAdjacentHTML('beforeend', str);});
	};
	
	// 在元素开头插入内容 | 例：at('.class').prepend(str)
	at.fn.prepend = function (str) {
		return this.each(function () {this.insertAdjacentHTML('afterbegin', str);});
	};
	
	// 判断样式是否存在 | 例：at().hasClass(str)
	at.fn.hasClass = function (str) {
		return this.each(function () {return this.classList.contains(str);}, 1);
	};
	
	// 添加class | 例：at('.class').addClass(str)
	at.fn.addClass = function (str) {
		return this.each(function () {return this.classList.add(str);});
	};
	
	// 除移class | 例：at('.class').removeClass(str)
	at.fn.removeClass = function (str) {
		return this.each(function () {return this.classList.remove(str);});
	};
	// click点击事件 | 例：at('.class').click(function(){alert(this.innerText);});
	at.fn.click = function (f) { //click改为监听事件，
		if (typeof (f) == "function") { //重载，若含有参数就注册事件，无参数就触发事件
			this.each(function () {this.addEventListener("click", f);});
		} else {
			this.each(function () {
				var event = document.createEvent('HTMLEvents');
				event.initEvent("click", true, true);
				this.dispatchEvent(event);
			});
		}
	};
	
	// 创建元素 | 例：at('.class').tag(str)
	at.fn.tag = function (tag) {
		var dom = document.createElement(tag);
		this[0] = dom; return this;
	};
	
	// 创建dom | 例：at('.class').dom(str)
	at.fn.dom = function (str) {
		var dom = document.createElement('p');
		dom.innerHTML = str; this[0] = dom.childNodes[0];
		return this;
	};
	
	/************
	* Obj 拓展
	************/
	at.ver = function () {return "0.0.1";};
	
	window.at = at;
}));
